import { ApiExtraModels, ApiProperty, getSchemaPath } from "@nestjs/swagger";
import { CrudValidationGroups } from "@nestjsx/crud";
import { IsString } from "class-validator";
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { Assets } from "./assets.entity";
import { BaseEntity } from "./base.entity";
import { Village } from "./village.entity";
import { Group } from "./group.entity";

const { CREATE, UPDATE } = CrudValidationGroups;


@Entity()
export class AssetsType extends BaseEntity {
  @ApiProperty({
    description: '资产类型 -主键',
    required: false,
  })
  @PrimaryGeneratedColumn()
  id: number;

  
  @ApiProperty({
    example: 1,
    description: '所属村',
    required: true,
    oneOf: [
      {
        type: 'Number'
      },
      {
        $ref: getSchemaPath(Village)
      }
    ]
  })
  @ManyToOne(type => Village , Village => Village.assetsType, {
    eager: true
  })
  village ?: Number | Village


  @ApiProperty({
    example: '资产类型名字',
    description: '资产类型名字',
    required: true
  })
  @IsString({ always: true })
  @Column({
    type: "char",
    length: 255,
  })
  name : string


  @ApiProperty({
    example: 1,
    description: '资产 -> 有外键',
    required: false,
    type: Number
  })
  @OneToMany(type => Assets , Assets => Assets.type)
  assets ?: Assets
}